package co.angluzha.business.student.service.impl;

import co.angluzha.commons.redis.annotation.DistributedLock;
import co.angluzha.commons.redis.utils.RedisLock;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import co.angluzha.business.student.dao.StudentDao;
import co.angluzha.data.student.entity.Student;
import co.angluzha.business.student.service.StudentService;
import com.ken.event.action.apply.producer.EventTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * 学生表(Student)表服务实现类
 *
 * @author makejava
 * @since 2022-11-22 11:14:38
 */
@Service("studentService")
@Slf4j
public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> implements StudentService {

    @Override
    @Cacheable(cacheNames = "Student",key = "'One:'+#id")
    @DistributedLock("'MyLock::'+ #id")
    @Transactional
    public Student getById(Serializable id) {
        log.warn("[student] id查询开始了{}",id);
        return super.getById(id);
    }

    @Override
    @Cacheable(cacheNames = "Student",key = "'List'")
    public List<Student> list() {
        EventTemplate.sendQuickly("stu-queue",new Student().setSname("Hello"));
        log.warn("[student] list查询开始了");
        return super.list();
    }

    @Override
    @CacheEvict(cacheNames = "Student",key = "'List'")
    public boolean save(Student entity) {
        log.warn("[student] 保存操作开始了");
        return super.save(entity);
    }

    @Override
    @CacheEvict(cacheNames = "Student",key = "'List'")
    public boolean updateById(Student entity) {
        log.warn("[student] id修改开始了{}",entity.getId());
        return super.updateById(entity);
    }
}

